
// 调用后端的接口,拿到本次开奖数据
function getSomeData() {

    return new Promise((resolve, reject) => {
        $.ajax({
            type: "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url: "http://39.98.41.34:28999/cp/getCpList?num=10",
            //数据，json字符串
            data: {},
            //请求成功
            success: function (result) {
                resolve(result)
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                reject(e)
            }
        });
    })
}
ready()
// 页面开始加载
async function ready() {
    let result = await getSomeData()
    const arrayList = result
    $(".dingWei>li").click(async function () {
        var $other = $(this).children(".dingwei-wap");
        $other.slideDown(100);
        var $anOther = $(this).siblings().children(".dingwei-wap");
        $anOther.slideUp(100);
    })

    $(".dingWei .dingwei-wap>li").click(function () {
        $("#middle-table tbody").remove()
        $("li").css("color", "white")
        $(this).css("color", "red")
        var index = $(this).parents(".dingWei>li").index();
        //万千百十个 
        $(".class-title div").remove()
        if ((index == 3) && ($(this).text() == "邻期和")) {
            $(".class-title div").remove()
            var title = "<div>前三</div><div>万千十</div><div>万千个</div><div>万百十</div><div>万百个</div><div>万十个</div><div>中三</div>" +
                "<div>千百个</div><div>千十个</div><div>后三</div>"
            $(".class-title").append(title);
            $(".class-title div").click(function () {
                $(".class-title div").css("color", "black")
                $(this).css("color", "red")
                $("#middle-table tbody").remove()
                if ($(this).text() == "前三") {
                    otherAddTr("012")
                }
                if ($(this).text() == "万千十") {
                    otherAddTr("013")
                }
                if ($(this).text() == "万千个") {
                    otherAddTr("014")
                }
                if ($(this).text() == "万百十") {
                    otherAddTr("023")
                }
                if ($(this).text() == "万百个") {
                    otherAddTr("024")
                }
                if ($(this).text() == "万十个") {
                    otherAddTr("034")
                }
                if ($(this).text() == "中三") {
                    otherAddTr("123")
                }
                if ($(this).text() == "千百个") {
                    otherAddTr("124")
                }
                if ($(this).text() == "千十个") {
                    otherAddTr("134")
                }
                if ($(this).text() == "后三") {
                    otherAddTr("234")
                }
            })
        }

        if ((index == 3) && ($(this).text() == "任2码和")) {
            $(".class-title div").remove()
            var title = "<div>前三</div><div>万千十</div><div>万千个</div><div>万百十</div><div>万百个</div><div>万十个</div><div>中三</div>" +
                "<div>千百个</div><div>千十个</div><div>后三</div>"
            $(".class-title").append(title);

            $(".class-title div").click(function () {
                $(".class-title div").css("color", "black")
                $(this).css("color", "red")
                $("#middle-table tbody").remove()
                if ($(this).text() == "前三") {
                    addTr("012")
                }
                if ($(this).text() == "万千十") {
                    addTr("013")
                }
                if ($(this).text() == "万千个") {
                    addTr("014")
                }
                if ($(this).text() == "万百十") {
                    addTr("023")
                }
                if ($(this).text() == "万百个") {
                    addTr("024")
                }
                if ($(this).text() == "万十个") {
                    addTr("034")
                }
                if ($(this).text() == "中三") {
                    addTr("123")
                }
                if ($(this).text() == "千百个") {
                    addTr("124")
                }
                if ($(this).text() == "千十个") {
                    addTr("134")
                }
                if ($(this).text() == "后三") {
                    addTr("234")
                }

            })

        }

    })
    // 添加表头 并且给出计算公式
    function otherAddTr(a) {
        var html =
            "<tr style='background:rgb(231,233,234)'>" +
            "<td>期数</td>" +
            "<td>号码</td>" +
            "<td>0</td>" +
            "<td>1</td>" +
            "<td>2</td>" +
            "<td>3</td>" +
            "<td>4</td>" +
            "<td>5</td>" +
            "<td>6</td>" +
            "<td>7</td>" +
            "<td>8</td>" +
            "<td>9</td>" +
            "<td>10</td>" +
            "<td>11</td>" +
            "<td>12</td>" +
            "<td>13</td>" +
            "<td>14</td>" +
            "<td>15</td>" +
            "<td>16</td>" +
            "<td>17</td>" +
            "<td>18</td><tr>"
        var inhtml = ""

        arrayList.forEach((item, key) => {
            let opencode = item.opencode.replace(/,/g, "")
            if (key < 9) {
                let showNumber = opencode[a[0]] + opencode[a[1]] + opencode[a[2]]
                let opencodeTwo = arrayList[key + 1].opencode.replace(/,/g, "")
                let newNumber = [opencode[a[0]] * 1 + opencodeTwo[a[0]] * 1, opencode[a[1]] * 1 + opencodeTwo[a[1]] * 1, opencode[a[2]] * 1 + opencodeTwo[a[2]] * 1]
                inhtml += changeTableAnd(showNumber, item.expect, newNumber)
            }
            if (key == 9) {
                let showNumber = opencode[a[0]] + opencode[a[1]] + opencode[a[2]]
                let newNumber = [opencode[a[0]] * 1, opencode[a[1]] * 1, opencode[a[2]] * 1]
                inhtml += changeTableAnd(showNumber, item.expect, newNumber)
            }

        })

        $("#middle-table").append(html + inhtml);
        $("#middle-table td").css({ "width": "50px", "text-align": "center", "height": "50px", })
        $("#middle-table td div").css({ "width": "30px", "color": "white", "text-align": "center", "position": "relative", "height": "30px", "line-height": "30px", "margin-top": "5px", "margin-left": "10px", "border-radius": "50%" })
        $("#middle-table td span").addClass("span-in")
        $("#middle-table td").addClass("border")
        $("#middle-table").addClass("bordertable")
    }
    // 添加表头 并且给出计算公式
    function addTr(a) {
        var html =
            "<tr style='background:rgb(231,233,234)'>" +
            "<td>期数</td>" +
            "<td>号码</td>" +
            "<td>0</td>" +
            "<td>1</td>" +
            "<td>2</td>" +
            "<td>3</td>" +
            "<td>4</td>" +
            "<td>5</td>" +
            "<td>6</td>" +
            "<td>7</td>" +
            "<td>8</td>" +
            "<td>9</td>" +
            "<td>10</td>" +
            "<td>11</td>" +
            "<td>12</td>" +
            "<td>13</td>" +
            "<td>14</td>" +
            "<td>15</td>" +
            "<td>16</td>" +
            "<td>17</td>" +
            "<td>18</td><tr>"
        var inhtml = ""

        arrayList.forEach((item, key) => {
            let opencode = item.opencode.replace(/,/g, "")

            let showNumber = opencode[a[0]] + opencode[a[1]] + opencode[a[2]]

            let newNumber = [opencode[a[0]] * 1 + opencode[a[1]] * 1, opencode[a[0]] * 1 + opencode[a[2]] * 1, opencode[a[1]] * 1 + opencode[a[2]] * 1]

            inhtml += changeTableAnd(showNumber, item.expect, newNumber)
        })

        $("#middle-table").append(html + inhtml);
        $("#middle-table td").css({ "width": "50px", "text-align": "center", "height": "50px", })
        $("#middle-table td div").css({ "width": "30px", "color": "white", "text-align": "center", "position": "relative", "height": "30px", "line-height": "30px", "margin-top": "5px", "margin-left": "10px", "border-radius": "50%" })
        $("#middle-table td span").addClass("span-in")
        $("#middle-table td").addClass("border")
        $("#middle-table").addClass("bordertable")
    }


    //添加每一行的数据
    function changeTableAnd(today, data, number) {

        let flag1 = number[0] == number[1]
        let flag2 = number[1] == number[2]
        let flag3 = number[0] == number[2]
        let html
        html += "<tr>";
        html += "<td style='background:rgb(231,233,234)'>" + data + "</td>"
        html += "<td style='background:rgb(231,233,234)'>" + today + "</td>"
        for (let i = 0; i < 19; i++) {

            if (number[0] == i + 1) {

                if (flag1 || flag3) {
                    html += "<td ><div style='background:	#FF00FF'>" + number[0] + "<span>2</span></div>" + "</td>"
                } else {
                    html += "<td ><div style='background:	red'>" + number[0] + "</div ></td>"
                }
            } else if
                (number[1] == i + 1) {

                if (flag2 || flag1) {
                    html += "<td ><div style='background:	#FF00FF'>" + number[1] + "<span>2</span></div>" + "</td>"
                } else {
                    html += "<td ><div style='background:	red'>" + number[1] + "</div ></td>"
                }
            } else
                if (number[2] == i + 1) {
                    if (flag3 || flag2) {
                        html += "<td ><div style='background:	#FF00FF'>" + number[2] + "<span>2</span></div>" + "</td>"
                    } else {
                        html += "<td ><div style='background:	red'>" + number[2] + "</div>" + "</td>"
                    }
                } else {
                    html += "<td style='background:rgb(255,253,243)'><div>" + "</div ></td>"
                }



        }
        html += "</tr>";

        return html

    }

}
